package com.wander.concurrent.queue;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

public class SynchronousQueueExample {
    public static void main(String[] args) {
        SynchronousQueue<Object> queue = new SynchronousQueue<>();
        new Thread(()->{
            try {
                System.out.println("3秒收放入数据：" + "hello");
                TimeUnit.SECONDS.sleep(3);
                queue.put("hello");
                queue.put("world");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }).start();
        new Thread(()->{
            Object take = null;
            try {
                take = queue.take();
                TimeUnit.SECONDS.sleep(3);
                System.out.println(queue.take());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(take);
        }).start();
    }
}
